<html>
<script type="text/javascript" src="<?=$ROOT_JS_DIR?>/common.js"></script>
<script type="text/javascript" src="<?=$ROOT_JS_DIR?>/jsmasks.js"></script>
<body>
<h1>Loading data...</h1>
<?

define("PRIMARY_KEY","nik");
$FileName       = "ais_transaction_receipt_entry_rpc.php";
$HTMLFormName   = "AdvanceForm";

if (GetParam("tglbkt","") && GetParam("curr","")) {
    list($day,$month,$year) = explode("/",GetParam("tglbkt",""));
    $SQL = "SELECT rate FROM ais_kurssi WHERE tglbkt <= '$year-$month-$day' AND curr='".GetParam("curr","")."' ORDER BY tglbkt DESC LIMIT 1";
//  print $SQL;
    $rate = $DBConnection->dbc->get_var($SQL);
    if ($rate) {
        $js_script  = "<script>\n";
        $js_script .= "  parent.document.".$HTMLFormName.".rate.value = '$rate';\n";
        $js_script .= "  oMask = new Mask('#,###.#0', 'number');\n";
        $js_script .= "  parent.document.".$HTMLFormName.".rate.value = oMask.format(parent.document.$HTMLFormName.rate.value);\n";
        $js_script .= "</script>\n";
        print $js_script;
    } else {
        $js_script  = "<script>\n";
        $js_script .= "  parent.document.".$HTMLFormName.".rate.value = '0';\n";
        $js_script .= "  oMask = new Mask('#,###.#0', 'number');\n";
        $js_script .= "  parent.document.".$HTMLFormName.".rate.value = oMask.format(parent.document.$HTMLFormName.rate.value);\n";
        $js_script .= "</script>\n";
        print $js_script;
    }
} elseif (GetParam("thbl","")) {
    $SQL   = "SELECT skada FROM tblreceipt WHERE kdreceipt=".GetParam("thbl","");
    $skada = $DBConnection->dbc->get_var($SQL);
    if (strlen($skada)) {
        $js_script  = "<script>\n";
        $js_script .= "  parent.document.$HTMLFormName.skada1.value = '$skada'";
        $js_script .= "</script>\n";
    } else {
        $js_script  = "<script>\n";
        $js_script .= "  parent.document.$HTMLFormName.skada1.value = ''";
        $js_script .= "</script>\n";
    }
    print $js_script;
} elseif (GetParam("ledger","") && GetParam("trsto","")) {
        list($day,$month,$year) = explode("/",GetParam("ledger",""));
        $SQL   = "SELECT count(*) FROM ais_history_ledger WHERE month='$month' AND year = '$year' AND status='open'";
        $ExistPeriod = $DBConnection->dbc->get_var($SQL);
        if (!$ExistPeriod) {
            $js_script  = "<script>\n";
            $js_script .= "  parent.document.$HTMLFormName.".GetParam("trsto","").".value = '';\n";
            $js_script .= "  alert('Invalid Date, Period Allready Closed!');\n";
            $js_script .= "  parent.document.$HTMLFormName.".GetParam("trsto","").".focus();\n";
            $js_script .= "</script>\n";
        }
    print $js_script;
}

?>
